package logic

import (
	"context"
	"zhaowei/models/mysql"

	"zhaowei/baidurpc/baidurpc"
	"zhaowei/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPostAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostAddLogic {
	return &PostAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PostAddLogic) PostAdd(in *baidurpc.PostAddRequest) (*baidurpc.PostAddResponse, error) {
	// todo: add your logic here and delete this line
	var post = mysql.Post{
		UserId: int(in.UserId),
		Name:   in.Name,
		Image:  in.Image,
		Like:   int(in.Like),
		BarId:  int(in.BarId),
	}
	mysql.DB.Debug().Create(&post)
	return &baidurpc.PostAddResponse{
		Id: int64(post.ID),
	}, nil
}
